****** Emerging Researchers NSF Project 
****** The Impact of Federal R&D Funding Across the Academy: An Analysis of Early-Career Research Productivity  
****** Data Code: Part 3 - Long Form Analysis
****** Built October 2018, Public Version Created June 2019 

********************************************************************************

*** Open Data File for Part 3 (P3)
** Set Directory Path 

********************************************************************************

*** Part 1: Primary Analysis
 
** Variables Globals 
global ddgrfp treatgrfp award postgrfp 
global ddthres treatthres award postthres
global picontrols priorpubs female ADV1female gendermatch
global gradinst gradpublic flagship_dc_invariant gradlandgrant
global gradprogram rank1 size1 size2 size3 avg_pubs_per_fac_nrc_dept female_fac_pct_nrc_dept avg_citations_per_pub_nrc_dept avg_GRE_nrc_dept grfpTot_iped_dept_prior2yr

** Threshold/Machine Learning Estimations
* Threshold Model
quietly reg total_article_cum award 
*outreg2 using "$dir/Threshold.xls", replace 
/* Allow sufficient time for processing 
threshold total_article_cum $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, regionvars(award) threshvar(panel)
outreg2 using "$dir/Threshold.xls", append dec(3) ctitle(CEM) 
threshold total_article_cum $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if fullsample == 1, regionvars(award) threshvar(panel)
outreg2 using "$dir/Threshold.xls", append dec(3) ctitle(Full) 
*/ 

* Machine Learning Model 
quietly reg total_article_cum award 
*outreg2 using "$dir/MachineLearningFull.xls", replace 
*outreg2 using "$dir/MachineLearningCEM.xls", replace 
forvalues i = 6(1)15 {
gen postpd = panel > `i'
reg total_article_cum postpd##award $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if mod(pi_id_unique,2)==0 
*outreg2 using "$dir/MachineLearningFull.xls", append dec(3) ctitle(Full Training)  
reg total_article_cum postpd##award $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if mod(pi_id_unique,2)==1
*outreg2 using "$dir/MachineLearningFull.xls", append dec(3) ctitle(Full Test)  

reg total_article_cum postpd##award $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if mod(pi_id_unique,2)==0 & cemsample == 1
*outreg2 using "$dir/MachineLearningCEM.xls", append dec(3) ctitle(CEM Training)  
reg total_article_cum postpd##award $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if mod(pi_id_unique,2)==1 & cemsample == 1
*outreg2 using "$dir/MachineLearningCEM.xls", append dec(3) ctitle(CEM Test)  
drop postpd
} 

** DD on Peer Reviewed Publications by Division with GRFP and Threshold Cutoff Years on CEM CCA sample
* DD with GRFP Shock
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDGRFP.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDGRFP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDGRFP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDGRFP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDGRFP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

* DD with Threshold Shock 
quietly reg total_article_cum $ddthres $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDThres.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, Threshold Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddthres $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDThres.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, Threshold Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddthres $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDThres.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, Threshold Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddthres $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDThres.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, Threshold Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddthres $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/PrimaryDDThres.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, Threshold Year Omitted, Controls, Yes)

** Robustness Analysis of Fixed Effects with Time Trends 
* Baseline FE 
xtset pi_id_unique panel
xtreg total_article_cum treatgrfp i.panel if cemsample == 1, fe
*outreg2 using "$dir/FE_baseline.xls", replace dec(3) e(r2_a) ctitle(FE, Total Publications, CEM Sample) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
xtreg total_article_cum treatgrfp i.panel if cemsample == 1 & div_cd == 1, fe
*outreg2 using "$dir/FE_baseline.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Engineering) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
xtreg total_article_cum treatgrfp i.panel if cemsample == 1 & div_cd == 2, fe
*outreg2 using "$dir/FE_baseline.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Life Sciences) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
xtreg total_article_cum treatgrfp i.panel if cemsample == 1 & div_cd == 3, fe
*outreg2 using "$dir/FE_baseline.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Math & Physical Sciences) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
xtreg total_article_cum treatgrfp i.panel if cemsample == 1 & div_cd == 4, fe
*outreg2 using "$dir/FE_baseline.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Social Sciences & Psychology) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)

* Twoway FE 
	*This estimates within-student changes after treatment, after controlling for within-group time-specific dummy trends.
egen grouptime = group(cem_strata_3 panel)
reghdfe total_article_cum treatgrfp if cemsample == 1, a(pi_id_unique grouptime) vce(cluster cem_strata_3)
*outreg2 using "$dir/FE_twoway.xls", replace dec(3) e(r2_a) ctitle(FE, Total Publications, CEM Sample) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
reghdfe total_article_cum treatgrfp if cemsample == 1 & div_cd == 1, a(pi_id_unique grouptime) vce(cluster cem_strata_3)
*outreg2 using "$dir/FE_twoway.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Engineering) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
reghdfe total_article_cum treatgrfp if cemsample == 1 & div_cd == 2, a(pi_id_unique grouptime) vce(cluster cem_strata_3)
*outreg2 using "$dir/FE_twoway.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Life Sciences) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
reghdfe total_article_cum treatgrfp if cemsample == 1 & div_cd == 3, a(pi_id_unique grouptime) vce(cluster cem_strata_3)
*outreg2 using "$dir/FE_twoway.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Math & Physical Sciences) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)
reghdfe total_article_cum treatgrfp if cemsample == 1 & div_cd == 4, a(pi_id_unique grouptime) vce(cluster cem_strata_3)
*outreg2 using "$dir/FE_twoway.xls", append dec(3) e(r2_a) ctitle(FE, Total Publications, Social Sciences & Psychology) label addtext(Fixed Effects, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, No)

********************************************************************************

*** Part 4: Sensitivity Analyses 

** LogFunctional Form 
quietly reg ln_totalpubs $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Log.xls", replace dec(3) e(r2_a) ctitle(OLS DD, LN Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg ln_totalpubs $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Log.xls", append dec(3) e(r2_a) ctitle(OLS DD, LN Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg ln_totalpubs $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Log.xls", append dec(3) e(r2_a) ctitle(OLS DD, LN Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg ln_totalpubs $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Log.xls", append dec(3) e(r2_a) ctitle(OLS DD, LN Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg ln_totalpubs $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Log.xls", append dec(3) e(r2_a) ctitle(OLS DD, LN Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

** Non-Cohort Sample
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & fuzzy2_L == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_NonCohort.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Non-Cohort Sample) label addtext(Clustered by PI, Yes, Sample, CEM Non-Cohort, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & fuzzy2_L == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_NonCohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & fuzzy2_L == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_NonCohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & fuzzy2_L == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_NonCohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & fuzzy2_L == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_NonCohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

** Cohort Sample
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_L == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Cohort.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Cohort Sample) label addtext(Clustered by PI, Yes, Sample, CEM Cohort, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_L == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Cohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_L == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Cohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_L == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Cohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_L == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Cohort.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

** Swithcer Sample
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_NL == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Switcher.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Switcher Sample) label addtext(Clustered by PI, Yes, Sample, CEM Switcher, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_NL == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Switcher.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_NL == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Switcher.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_NL == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Switcher.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & direct_NL == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/Sensitive_Switcher.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

********************************************************************************

*** Part 5: Empirical Extensions 

** Descriptive Comparison on Superstars 
quietly reg total_article_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if superstar == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Outliers.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Outliers Sample) label addtext(Clustered by PI, Yes, Sample, Pub Outliers, Cutoff, GRFP Year Omitted, Controls, Yes)
ttest total_article_cum if superstar == 1, by(award)
ttest total_article_c5yr_cum if superstar == 1, by(award)
ttest auth_weighted_art if superstar == 1, by(award)
ttest auth_weighted_cit if superstar == 1, by(award)
ttest numauth_article if superstar == 1, by(award)
ttest numauth_art_cum if superstar == 1, by(award)

** Marginal Effect from Continuous Real Stipend Value of the Award
gen stipend_df_1k = grfp_stipend_df_1k
replace stipend_df_1k = 0 if award == 0
gen total_df_1k = grfp_total_df_1k
replace total_df_1k = 0 if award == 0

quietly reg total_article_cum c.stipend_df_1k##postgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & award == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Marginal.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum c.stipend_df_1k##postgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & award == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Marginal.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum c.stipend_df_1k##postgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & award == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Marginal.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum c.stipend_df_1k##postgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & award == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Marginal.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_cum c.stipend_df_1k##postgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & award == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/Ext_Marginal.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)

********************************************************************************

*** Part 6: Alterante Outcomes 

** Research Publications 	
quietly reg total_rpub_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_RP.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Total Research, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_rpub_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_RP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Research, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_rpub_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_RP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Research, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_rpub_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_RP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Research, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_rpub_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_RP.xls", append dec(3) e(r2_a) ctitle(OLS DD, Total Research, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)
	
** New Publications
* New Annual Publications 
quietly reg total_article $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", replace dec(3) e(r2_a) ctitle(OLS DD, New Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, New Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, New Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, New Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, New Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)
	
* Three-Year Moving Average of New Publications	
quietly reg newpub_moveavg3 $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, 3-Year Average New Publications, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg newpub_moveavg3 $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, 3-Year Average New Publications, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg newpub_moveavg3 $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, 3-Year Average New Publications, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg newpub_moveavg3 $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, 3-Year Average New Publications, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg newpub_moveavg3 $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_New.xls", append dec(3) e(r2_a) ctitle(OLS DD, 3-Year Average New Publications, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)
		
** Citations
quietly reg total_article_c5yr_cum $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_Cites.xls", replace dec(3) e(r2_a) ctitle(OLS DD, 5-Year Total Citations, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_c5yr_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_Cites.xls", append dec(3) e(r2_a) ctitle(OLS DD, 5-Year Total Citations, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_c5yr_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_Cites.xls", append dec(3) e(r2_a) ctitle(OLS DD, 5-Year Total Citations, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_c5yr_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_Cites.xls", append dec(3) e(r2_a) ctitle(OLS DD, 5-Year Total Citations, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg total_article_c5yr_cum $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_Cites.xls", append dec(3) e(r2_a) ctitle(OLS DD, 5-Year Total Citations, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)

** Author Weighted 
* Cumulative Publication Counts 
quietly reg auth_weighted_art $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWPubsCum.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Pubs, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_art $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWPubsCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Pubs, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_art $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWPubsCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Pubs, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_art $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWPubsCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Pubs, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_art $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWPubsCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Pubs, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)
	
* Cumulative Citation Counts in a Year
quietly reg auth_weighted_cit $ddgrfp $picontrols i.grfp_yr i.div_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWCitesCum.xls", replace dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Cites, CEM Sample) label addtext(Clustered by PI, Yes, Sample, CEM, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_cit $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 1, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWCitesCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Cites, Engineering) label addtext(Clustered by PI, Yes, Sample, CEM Eng, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_cit $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 2, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWCitesCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Cites, Life Sciences) label addtext(Clustered by PI, Yes, Sample, CEM LS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_cit $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 3, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWCitesCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Cites, Math & Physical Sciences) label addtext(Clustered by PI, Yes, Sample, CEM MPS, Cutoff, GRFP Year Omitted, Controls, Yes)
quietly reg auth_weighted_cit $ddgrfp $picontrols i.grfp_yr i.field_cd $gradinst i.gradtype_cc i.gradregion $gradprogram bacpublic i.bac_cd if cemsample == 1 & div_cd == 4, cluster(pi_id_unique)
*outreg2 using "$dir/AltOutcomes_AWCitesCum.xls", append dec(3) e(r2_a) ctitle(OLS DD, Author-Weighted Cum Cites, Social Sciences & Psychology) label addtext(Clustered by PI, Yes, Sample, CEM SSP, Cutoff, GRFP Year Omitted, Controls, Yes)
	
********************************************************************************
				                  *** END ***
********************************************************************************
